//
//  EJSGoodsDetailTableViewCell.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2017/12/26.
//  Copyright © 2017年 lifayu. All rights reserved.
//

#import "EJSGoodsDetailTableViewCell.h"
#import <MBProgressHUD.h>

@implementation EJSGoodsDetailTableViewCell{
    NSString *_content;
    CGFloat _webViewHeight;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _webView.delegate = self;
    _webView.scrollView.scrollEnabled = NO;
    [self setContent:@"<p>商品详情</p>"];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setContent:(NSString *)content{
    [MBProgressHUD hideHUDForView:self.contentView animated:YES];
    _content = content;
    if(content && content.length > 0){
        NSString *imgStyle=@"<style type=\"text/css\">img{max-width:100%;height:auto;} </style>";
        NSString *textFontString = [NSString stringWithFormat:@"<style type=\"text/css\">*{font-size:%0.0fpx; color:#343434} </style>",16.0];
        NSString *htmlString = [NSString stringWithFormat:@"%@%@%@", imgStyle, textFontString, content];
        [_webView loadHTMLString:htmlString baseURL:nil];
        [MBProgressHUD showHUDAddedTo:self.contentView animated:YES];
    }
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    CGSize fittingSize = [self.webView sizeThatFits:CGSizeZero];
    _webViewHeight = fittingSize.height;
    self.webViewHeightConstraint.constant = _webViewHeight;
    if(_content){
        [[NSNotificationCenter defaultCenter] postNotificationName:EJSGoodsDetailWebViewDidLoadNotify object:@(_webViewHeight).stringValue];
    }
    [MBProgressHUD hideHUDForView:self.contentView animated:YES];
}


@end
